package com.accp.wxmp.handler;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class EngineerHandler  extends AbstractHandler {
    @Autowired
    protected WxMpService wxMpService;
    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> map, WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
        WxMpXmlOutNewsMessage.Item item1 = new WxMpXmlOutNewsMessage.Item();
        item1.setTitle("汇鑫工程师");
        item1.setDescription("我是描述");
        item1.setPicUrl("http://47.95.222.72:8080/static/img/bj.jpg");
        item1.setUrl("http://47.95.222.72:8080/engineer/index?openid="+wxMessage.getFromUserName());
        WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS().
                addArticle(item1).
                fromUser(wxMessage.getToUserName()).
                toUser(wxMessage.getFromUserName()).
                build();
        return m;
    }
}
